package cn.kn.common.exception;

import cn.kn.common.model.R;
import cn.kn.common.model.RCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author WangJiang
 * @create 2020-12-08 9:01
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(CustomException.class)
    public R customExceptionHandler(CustomException e){
        return R.error(e.getRCode());
    }

    @ExceptionHandler(MissingServletRequestParameterException.class)
    public R missingServletRequestParameterException(MissingServletRequestParameterException e){
        log.error(e.getMessage());
        return R.error(RCode.PARM_ERROR);
    }

}
